package com.dkts.oil.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class DateUtil {
    public final static SimpleDateFormat DATE_FORMATOR = new SimpleDateFormat("yyyy-MM-dd");

    public static String[] getDaysByDuration(Date startDate, Date endDate) {
        List<String> days = new ArrayList<>();
        Date tempDate = startDate;
        while (DateUtil.DATE_FORMATOR.format(tempDate).compareTo(DateUtil.DATE_FORMATOR.format(endDate)) <= 0) {
            days.add(DateUtil.DATE_FORMATOR.format(tempDate));
            Calendar calender = Calendar.getInstance();
            calender.setTime(tempDate);
            calender.add(Calendar.DATE, 1);
            tempDate = calender.getTime();
        }
        return (String[]) days.toArray();
    }

    public static void main(String[] args) throws ParseException {


        Thread t1 = new Thread(new Task("A1"), "T1");
        Thread t2 = new Thread(new Task("A2"), "T2");
        
        t1.start();
        t2.start();
    }

    synchronized static void sleep() {
        try {
            //if (Thread.currentThread().getName().equals("T1"))
            //    Thread.sleep(100);
            System.out.println("   123");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

class Task implements Runnable {
    String user;

    public Task(String user) {
        this.user = user;
    }

    @Override
    public void run() {
        synchronized(this.user) {
            for (int i = 0; i <= 100; i++) {
                System.out.println(Thread.currentThread().getName() + " -- " + user + " - " + i);
                DateUtil.sleep();
            }
        }
    }
}
